home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / TIMER.H < prev    next >
Text File  |  1993-08-09  |  2KB  |  66 lines

  1. #ifndef    _TIMER_H
  2. #define _TIMER_H
  3.  
  4. #ifndef _GLOBAL_H
  5. #include "global.h"
  6. #endif
  7.  
  8. /* Software timers
  9.  * There is one of these structures for each simulated timer.
  10.  * Whenever the timer is running, it is on a linked list
  11.  * pointed to by "Timers". The list is sorted in ascending order of
  12.  * expiration, with the first timer to expire at the head. This
  13.  * allows the timer process to avoid having to scan the entire list
  14.  * on every clock tick; once it finds an unexpired timer, it can
  15.  * stop searching.
  16.  *
  17.  * Stopping a timer or letting it expire causes it to be removed
  18.  * from the list. Starting a timer puts it on the list at the right
  19.  * place.
  20.  */
  21. typedef enum {
  22.     TIMER_STOP   = 0,
  23.     TIMER_RUN    = 1,
  24.     TIMER_EXPIRE = 2,
  25. }Tistate;
  26.  
  27. struct timer {
  28.     struct timer *next;                /* Linked-list pointer */
  29.     int32 duration;                    /* Period of counter (load value) */
  30.     int32 expiration;                /* Ticks to go until expiration */
  31.     void (*func) __ARGS((void *));    /* Function to call at expiration */
  32.     void *arg;                        /* Arg to pass function */
  33.     Tistate state;                    /* Timer state */
  34. #ifdef MDEBUG
  35.     char tname[9];                    /* timer name DK5DC */
  36. #endif
  37. };
  38. #define    NULLTIMER    (struct timer *)0
  39.  
  40. #define    MAX_TIME    (int32)4294967295L    /* Max long integer */
  41. #ifndef    MSPTICK
  42. #define    MSPTICK        55        /* Milliseconds per tick */
  43. #endif
  44.  
  45. /* Useful user macros that hide the timer structure internals */
  46. #define    dur_timer(t)    ((t)->duration * MSPTICK)
  47. #define    run_timer(t)    ((t)->state == TIMER_RUN)
  48.  
  49. extern int Tick;
  50. extern void (*Cfunc[])();
  51.  
  52. /* In timer.c: */
  53. void alarm __ARGS((int32 ms));
  54. int pause __ARGS((int32 ms));
  55. int32 read_timer __ARGS((struct timer *t));
  56. void set_timer __ARGS((struct timer *t,int32 x));
  57. void start_timer __ARGS((struct timer *t));
  58. void stop_timer __ARGS((struct timer *timer));
  59. char *tformat __ARGS((int32 t));
  60. int32 msclock __ARGS((void));
  61. int32 secclock __ARGS((void));
  62.  
  63. #endif    /* _TIMER_H */
  64.  
  65.  
  66.